<template>
	<div class="system-user-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<div class="system-user-search mb15">
				生效日期：<el-input size="default" placeholder="请输入生效日期" style="max-width: 180px" v-model="state.tableData.param.effectiveDate"> </el-input> &nbsp; &nbsp; &nbsp; &nbsp; 
				版本号：<el-input size="default" placeholder="请输入版本号" style="max-width: 180px" v-model="state.tableData.param.name"> </el-input>
				<el-button size="default" type="primary" class="ml10" @click="getTableData()">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
				<el-button size="default" type="success" class="ml10" @click="onOpenAdd('add')">
					<el-icon>
						<ele-FolderAdd />
					</el-icon>
					新增版本号
				</el-button>
			</div>
			<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
				<el-table-column type="index" label="序号" width="60" />
				<el-table-column prop="createTime" label="上传时间" show-overflow-tooltip></el-table-column>
				<el-table-column prop="createUserName" label="上传人" show-overflow-tooltip></el-table-column>
				<el-table-column prop="fileName" label="文件名称" show-overflow-tooltip></el-table-column>
				<el-table-column prop="status" label="状态" show-overflow-tooltip></el-table-column>
				<el-table-column prop="result" label="处理结果" show-overflow-tooltip></el-table-column>
				<el-table-column label="操作" width="200">
					<template #default="scope">
						<el-button size="small" text type="primary" @click="onOpenEdit('edit', scope.row)">修改</el-button>
						<el-button size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				@size-change="onHandleSizeChange"
				@current-change="onHandleCurrentChange"
				class="mt15"
				:pager-count="5"
				:page-sizes="[10, 20, 30]"
				v-model:current-page="state.tableData.param.pageNum"
				background
				v-model:page-size="state.tableData.param.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="state.tableData.total"
			>
			</el-pagination>
		</el-card>
		<VersionNoDialog ref="versionNoDialogRef" @refresh="getTableData()" />
	</div>
</template>

<script setup lang="ts" name="systemUser">
import { defineAsyncComponent, reactive, onMounted, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { versionNoApi } from './api';

// 引入组件
const VersionNoDialog = defineAsyncComponent(() => import('/@/views/daily/interfaceDocUpload/dialog.vue'));
// 引入 api 请求接口
const api = versionNoApi();

// 定义变量内容
const versionNoDialogRef = ref();
const state = reactive({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			pageNum: 1,
			pageSize: 10,
			name:'',
			effectiveDate:''
		},
	},
});

// 初始化表格数据
const getTableData = async () => {
	state.tableData.loading = true;
	try {
		const res = await api.getList(state.tableData.param);
		state.tableData.data = res.data;
		state.tableData.total = res.total;
	} catch (error:any) {
		ElMessage.warning(error.message);
	}
	state.tableData.loading = false;
};
// 打开新增用户弹窗
const onOpenAdd = (type: string) => {
	versionNoDialogRef.value.openDialog(type);
};
// 打开修改用户弹窗
const onOpenEdit = (type: string, row: any) => {
	versionNoDialogRef.value.openDialog(type, row);
};
// 删除用户
const onRowDel = (row: any) => {
	ElMessageBox.confirm(`此操作将永久删除版本号：“${row.name}”，是否继续?`, '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning',
	}).then(() => {
		api.delete({'id':row.id}).then(
			(res) => {
				if (res.data.code === "000000") {
					ElMessage.success(res.data.message);
					getTableData();
				} else {
					ElMessage.warning(res.data.message);
				}
			}
		);
	}).catch(() => {});
};
// 分页改变
const onHandleSizeChange = (val: number) => {
	state.tableData.param.pageSize = val;
	getTableData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
	state.tableData.param.pageNum = val;
	getTableData();
};
// 页面加载时
onMounted(() => {
	getTableData();
});
</script>

<style scoped lang="scss">
.system-user-container {
	:deep(.el-card__body) {
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: auto;
		.el-table {
			flex: 1;
		}
	}
}
</style>
